<?php

namespace App\Module\Api\Controllers;
use App\Module\Api\Controllers\Request\GoodsDetailsRequest;
use App\Module\Api\Validator\CommonIdValidator;
use App\System\Base\Services\TokenService;
use App\System\Cis\Repositories\CisUserAddressRepository;

/**
 * 收货地址详细
 * @package App\Module\Admin\Controllers
 */
class AddressDetailsController extends Controller
{
    public function __construct()
    {
        $this->query = new GoodsDetailsRequest();
        parent::__construct();
    }

    public function index()
    {
        (new CommonIdValidator())->check();
        $address = CisUserAddressRepository::getInstance();
        $master_id = TokenService::getMasterId();
        $address_info = $address->getDetail($this->query->id,$master_id);
        if(!$address_info)
        {
            throw new ParamsException([
                'error_code' => '1011',
                'message'    => '地址不存在或已经删除',
            ]);
        }

        $data['id'] = $address_info->id;
        $data['name'] = $address_info->consignee;
        $data['mobile'] = $address_info->mobile;
        $data['isDefault'] = $address_info->is_default;
        $data['regionId'] = $address_info->region_id;
        $data['regionInfo'] = $address_info->region_info;
        $data['street'] = $address_info->street;
        $data['address'] = $address_info->address_info;
        $data['street'] = $address_info->street;

        return apiResponse(['address'=>$data]);
    }
}
